package com.hnkj.caiyunweather.ui.place

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.hnkj.caiyunweather.logic.Repostory
import com.hnkj.caiyunweather.logic.model.Place

class PlaceViewModel:ViewModel() {
    private val searchLiveData = MutableLiveData<String>()

    val placeList = ArrayList<Place>()

    val placeLiveData = Transformations.switchMap(searchLiveData){
        Repostory.searchPlaces(it)
    }
    fun searchPlaces(placeName:String){
        searchLiveData.value = placeName
    }


    fun savePlace(place:Place) = Repostory.savePlace(place)

    fun getSavedPlace() = Repostory.getSavedPlace()

    fun isPlaceSaved() = Repostory.isPlaceSaved()
}